
package com.be.beadmin.project.repository;

import com.be.beadmin.project.entity.ProductInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @author zjm
* @date 2023-02-13
**/
public interface ProductInfoRepository extends JpaRepository<ProductInfo, String>, JpaSpecificationExecutor<ProductInfo> {

    ProductInfo findProductInfoByIdAndDelete(String id, Integer delete);

    ProductInfo findProductInfoById(String id);

    List<ProductInfo> findProductInfoByInfoIdAndDelete(String infoId, Integer delete);

    List<ProductInfo> findProductInfoByProductTypeAndDelete(String ProductType, Integer delete);

    int countProductInfoByProductTypeAndDelete(String ProductType, Integer delete);

    @Modifying
    @Transactional
    @Query(value = "update t_pm_product_info pi set pi.is_delete = ?1 where pi.info_id = ?2 and pi.is_delete = ?3",nativeQuery = true)
    void deleteProductInfoByInfoIdAndDelete(int deleted, String infoId,int nodelete);


    @Modifying
    @Transactional
    @Query(value = "update t_pm_product_info pi set pi.is_delete = ?1 where pi.id = ?2",nativeQuery = true)
    void deleteProductInfoById(int deleted, String id);

    List<ProductInfo> findProductInfoByProjectNameAndDelete(String ProjectName , Integer delete);
}